﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Models;
using Service.Interface;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebAPI.CustomFilter;

namespace WebAPI.Controllers
{

    /// <summary>
    /// 工序处理
    /// </summary>
    [ApiController]
    [Route("[controller]/[action]")]
    public class ProcessController : ControllerBase
    {
        Result result = new Result(true);
        private readonly ILogger<ProcessController> _logger;
        private readonly IServices _services;
        private readonly IFlowServices _flowservices;
        private readonly IJobHeadServices _jobheadservices;
        private readonly IShipmentServices _shipmentservices;

        public ProcessController(ILogger<ProcessController> logger, IServices services, IFlowServices flowServices, IJobHeadServices jobheadservices,IShipmentServices shipmentServices )
        {
            _logger = logger;
            _services = services;
            _flowservices = flowServices;
            _jobheadservices = jobheadservices;
            _shipmentservices = shipmentServices;
        }

        /// <summary>
        /// 工单创建通知FIS 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Result GetJobHead(List<JobHead> JobHead)
        {
            return new Result(_jobheadservices.AddJobHead(JobHead));
        }

        /// <summary>
        /// 同步工艺 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Result GetProcessFlow(ProcessFlow flow)
        {
            result.ReturnData = _flowservices.GetProcessFlowByProduct(flow);
            return result;
        }

        /// <summary>
        /// 同步成品出货
        /// </summary>
        /// <param name="shipments"></param>
        /// <returns></returns>
        [HttpPost]
        public Result SynProductShipment(List<ProductShipment> shipments)
        {
            return new Result(_shipmentservices.SynProductShipment(shipments));
        }

        /// <summary>
        /// 获取工序
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Result GetProcessName()
        {
            result.ReturnData = _flowservices.GetProcessName();
            return result;
        }

        /// <summary>
        /// 获取返修工序
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Result GetReworkCategory()
        {
            result.ReturnData = _flowservices.GetReworkCategory(string.Empty);
            return result;
        }

        /// <summary>
        /// 更新设备状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Result SynEquipment(List<EquipmentInfo> equipment)
        {
            result.ReturnData = _flowservices.SynEquipment(equipment);
            return result;
        }

    }
}
